package com.giao.controller;

import com.giao.pojo.ContractC;
import com.giao.service.ContractService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/contract")
public class ContractController {
    @Resource
    private ContractService contractService;

    //查询全部
    @RequestMapping("/findContract")
    public String findContract(Model model) {
        List<ContractC> contractProductCS = contractService.findAllContract();
        model.addAttribute("o", contractProductCS);
        return "basicinfo/factory/jContractList";
    }

    //删除
    @RequestMapping("/deleteContract/{contract_id}")
    public String deleteContract(@PathVariable("contract_id") int id) {
        contractService.deleteContract(id);
        return "redirect:/contract/findContract";
    }

    //去修改页面
    @RequestMapping("/jContractProductCreate")
    public String ToUpdateContract(int id, Model model) {
        ContractC contractC = contractService.findByContractId(id);
        model.addAttribute("contractC", contractC);
        return "basicinfo/factory/jContractUpdate";
    }

    //修改
    @RequestMapping("/updateContract")
    public String updateContract(ContractC contractC) {
        contractService.updateContract(contractC);
        return "redirect:/contract/findContract";
    }

    //跳转到添加页面
    @RequestMapping("/jContractCreate")
    public String toInsertContract() {
        return "basicinfo/factory/jContractCreate";
    }

    //添加
    @RequestMapping("/insertContract")
    public String insertContract(ContractC contractC) {
        contractService.insertContract(contractC);
        return "redirect:/contract/findContract";
    }

    //状态修改
    @RequestMapping("/startC")
    public String startC(Integer contract_id) {
        contractService.updatestartokC(contract_id);
        return "redirect:/contract/findContract";
    }

    @RequestMapping("/stopC")
    public String stopC(Integer contract_id) {
        contractService.updatestartnoC(contract_id);
        return "redirect:/contract/findContract";
    }

}
